home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / dev / c / appsource.lha / APlusPlus / TESTPRGS / intuition / GT_test.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-29  |  7.9 KB  |  281 lines

  1. /******************************************************************************
  2.  *
  3.  *    $Source: apphome:RCS/testprgs/intuition/GT_test.cxx,v $
  4.  *
  5.  *    Demo for the A++ Library
  6.  *    Copyright (C) 1994 by Armin Vogt, EMail: armin@uni-paderborn.de
  7.  *
  8.  *    $Revision: 1.8 $
  9.  *    $Date: 1994/07/23 19:15:33 $
  10.  *    $Author: Armin_Vogt $
  11.  *
  12.  ******************************************************************************/
  13.  
  14.  
  15. #include <APlusPlus/exec/SignalResponder.h>
  16. #include <APlusPlus/intuition/GWindow.h>
  17. #include <APlusPlus/gadtools/GT_Scroller.h>
  18. #include <APlusPlus/gadtools/GT_String.h>
  19. #include <APlusPlus/gadtools/GT_Boolean.h>
  20. #include <APlusPlus/intuition/BoopsiGadget.h>
  21. #include <APlusPlus/graphics/AutoDrawArea.h>
  22. #include <APlusPlus/intuition/ITransponder.h>
  23. #include <APlusPlus/intuition/IntuiMessageC.h>
  24. #include <APlusPlus/graphics/GBorder.h>
  25.  
  26.  
  27. extern "C" {
  28. #include <dos/dos.h>
  29. }
  30.  
  31.  
  32. static const char rcs_id[] = "$Id: GT_test.cxx,v 1.8 1994/07/23 19:15:33 Armin_Vogt Exp Armin_Vogt $";
  33.  
  34.  
  35. BOOL running = TRUE;
  36. BOOL close2 = FALSE;
  37. GWindow *stop_window;
  38.  
  39.  
  40. class MySRSP : public SignalResponder
  41. {
  42.    public:
  43.       MySRSP(BYTE signal) : SignalResponder(signal,0) {}
  44.       ~MySRSP() {}
  45.       // overload the virtual 'signal received' action callback method.
  46.       void actionCallback()
  47.       {
  48.          puts("**Break\n");
  49.          running = FALSE;
  50.       }
  51. };
  52.  
  53.  
  54. class MyWindow : public GWindow
  55. {
  56.    private:
  57.       void init()
  58.       {
  59.          modifyIDCMP(CLASS_NEWSIZE|CLASS_CLOSEWINDOW|CLASS_ACTIVEWINDOW|CLASS_SIZEVERIFY);
  60.       }
  61.  
  62.    public:
  63.       MyWindow(OWNER,AttrList& attrs) : GWindow(owner,attrs) { init(); }
  64.       ~MyWindow() {}
  65.  
  66.       void On_CLOSEWINDOW(const IntuiMessageC *msg)
  67.       {
  68.          puts("CLOSEWINDOW.\n");
  69.          if (this == stop_window) running = FALSE;
  70.          else close2 = TRUE;
  71.       }
  72.       void On_ACTIVEWINDOW(const IntuiMessageC *msg)
  73.       {
  74.          ULONG dummy=0;
  75.          printf("%s is ACTIVE.\n",getAttribute(WA_Title,dummy));
  76.       }
  77.       void On_SIZEVERIFY(const IntuiMessageC *msg)
  78.       {
  79.          puts("SIZEVERIFY. \n");
  80.       }
  81.       void handleIntuiMsg(const IntuiMessageC* imsg)
  82.       {
  83.          switch (imsg->getClass())
  84.          {
  85.             case CLASS_CLOSEWINDOW :
  86.                On_CLOSEWINDOW(imsg); break;
  87.             case CLASS_ACTIVEWINDOW :
  88.                On_ACTIVEWINDOW(imsg); break;
  89.             case CLASS_SIZEVERIFY :
  90.                On_SIZEVERIFY(imsg); break;
  91.          }
  92.          GWindow::handleIntuiMsg(imsg);
  93.       }
  94.  
  95. };
  96.  
  97. class BoolGadget : public GT_Boolean, public ITransponder
  98. {
  99.    protected:
  100.       // this method will be called each time the user clicks on the button
  101.       // the attrs contains the Attribute Tag GA_ID,<gadget_id> to identify the sending gadget.
  102.       // <gadget_id> is the value that has been given on the constructor attribute list
  103.       // of an object of this class.
  104.       void sendNotification(AttrList& attrs)
  105.       {
  106.          printf("GT_Boolean hit: GA_ID=%ld\n",attrs.getTagData(GA_ID,-1));
  107.       }
  108.    public:
  109.       BoolGadget(GOB_OWNER,AttrList& attrs) : GT_Boolean(gob_owner,attrs)
  110.       {
  111.          // since this class is composed of a Gadget plus its ITransponder
  112.          // it has to announce its ITransponder to the Gadget.
  113.          // Due to the use of 'setAttributes()' both base class AND class user
  114.          // ITransponder settings will be overwritten!
  115.          // IMPORTANT: the call of a virtual method within a CONSTRUCTOR is
  116.          // UNDEFINED! Therefore you MUST qualify the base class with the 
  117.          // scope resolution operator '::' to suppress the virtual mechanism.
  118.          GT_Boolean::setAttributes( AttrList(ITRANSPONDER(this), TAG_END) );
  119.       }
  120.       ~BoolGadget() {}
  121.    
  122.       // runtime type inquiry support
  123.       static const Intui_Type_info info_obj;
  124.       virtual const Type_info& get_info() const     // get the 'type_id' to an existing object
  125.          { return info_obj; }
  126.       static const Type_info& info()                // get the 'type_id' of a specific class
  127.          { return info_obj; }
  128. };
  129.  
  130. intui_typeinfo(BoolGadget, derived(from(GT_Boolean)), rcs_id);
  131.  
  132.  
  133. void APPmain(int argc,char* argv[])
  134. {
  135.    MySRSP sr(SIGBREAKB_CTRL_C);
  136.  
  137.    NeXTBorder border;
  138.  
  139.    MyWindow *little = new MyWindow(OWNER_NULL,
  140.    AttrList(  WA_Title,"WindowC - close this to stop.",
  141.       WA_Width,300,
  142.       WA_Height,150,
  143.       WA_MinHeight,50,
  144.       WA_MinWidth,50,
  145.       WA_MaxHeight,1000,
  146.       WA_MaxWidth,1000,
  147.       WA_DragBar,TRUE,
  148.       WA_SizeGadget,TRUE,
  149.       WA_DepthGadget,TRUE,
  150.       WA_CloseGadget,TRUE,
  151.       WA_IDCMP,TRUE,
  152.       GOB_BorderObj(&border),
  153.       GOB_BorderTitle,(UBYTE*)"Boopsi & GadTools",
  154.       GOB_BackgroundColor,5,
  155.       TAG_END) );
  156.  
  157.  
  158.    class Boopsi2GTSC : public ITransponder
  159.    {
  160.       private:
  161.       public:
  162.          virtual void sendNotification(AttrList& attrs)
  163.          {
  164.             attrs.mapAttrs(PGA_Top, GTSC_Top, GA_ID,GA_ID, TAG_END);
  165.  
  166.             puts("   notification received "); attrs.print();
  167.             if (APPOK(receiver1))
  168.             {
  169.                if(receiver1->setAttributes(attrs)) puts("   visual change\n");
  170.             }
  171.             else printf(" receiver(%lx) is INVALID!\n",(APTR)this);
  172.             puts("   notification forwarded.\n");
  173.          }
  174.    }
  175.    boopsi2GTSC;
  176.  
  177.    class GTSC2Boopsi : public ITransponder
  178.    {
  179.       private:
  180.       public:
  181.          virtual void sendNotification(AttrList& attrs)
  182.          {
  183.             attrs.mapAttrs( GTSC_Top,PGA_Top, GA_ID,GA_ID,TAG_END);
  184.  
  185.             puts("   notification received "); attrs.print();
  186.             if (APPOK(receiver1))
  187.             {
  188.                if(receiver1->setAttributes(attrs)) puts("   visual change\n");
  189.             }
  190.             else printf(" receiver(%lx) is INVALID!\n",(APTR)this);
  191.             puts("   notification forwarded.\n");
  192.          }
  193.    } GTSC2boopsi;
  194.  
  195.  
  196.    GTSC2boopsi.setReceiver( new BoopsiGadget(little,
  197.       (UBYTE*)"propgclass",
  198.    AttrList(
  199.       GOB_LeftFromRightOfParent,-20,
  200.       GOB_TopFromTopOfParent,1,
  201.       GOB_RightFromRightOfParent,-1,
  202.       GOB_BottomFromBottomOfParent,-1,
  203.       GA_Immediate,TRUE,
  204.       GA_RelVerify,TRUE,
  205.       PGA_Freedom,FREEVERT,
  206.       PGA_Top,1,
  207.       PGA_Total,20,
  208.       PGA_Visible,5,
  209.       ICA_TARGET,ICTARGET_IDCMP,
  210.       PGA_NewLook,TRUE,
  211.       ITRANSPONDER(&boopsi2GTSC),
  212.       TAG_END)) );
  213.  
  214.  
  215.    boopsi2GTSC.setReceiver( new GT_Scroller(little,
  216.    AttrList(
  217.       GOB_LeftFromLeftOfPred,-20,
  218.       GOB_TopFromTopOfPred,0,
  219.       GOB_RightFromLeftOfPred,-2,
  220.       GOB_BottomFromBottomOfPred,-10,
  221.       GA_Immediate,TRUE,
  222.       GA_RelVerify,TRUE,
  223.       PGA_Freedom,LORIENT_VERT,
  224.       GTSC_Top,1,
  225.       GTSC_Total,20,
  226.       GTSC_Visible,2,
  227.       GTSC_Arrows,8,
  228.       GT_IDCMP,SLIDERIDCMP,
  229.       ITRANSPONDER(>SC2boopsi),
  230.       GA_ID,2344,
  231.       TAG_END)) );
  232.  
  233.  
  234.    class StringOut : public ITransponder
  235.    {
  236.       protected:
  237.          // each time the user presses the return key in the string gadget
  238.          // a notification arrives here with the new GTST_String value pointing to
  239.          // the string in the edit buffer
  240.          void sendNotification(AttrList& attrs)
  241.          {
  242.             printf("GT_String: '%s'\n",(char*)attrs.getTagData(GTST_String,NULL));
  243.          }
  244.    } stringOut;
  245.  
  246.    new GT_String(little,
  247.    AttrList(
  248.       GOB_LeftFromLeftOfParent,10,
  249.       GOB_TopFromTopOfParent,10,
  250.       GOB_RightFromLeftOfPred,-10,
  251.       GOB_BottomFromTopOfParent,30,
  252.       GTST_String,(UBYTE*)"Enter here.",
  253.       GA_RelVerify,TRUE,
  254.       ITRANSPONDER(&stringOut),  // call 'stringOut::sendNotification' on attribute change.
  255.       TAG_END) );
  256.  
  257.  
  258.    new BoolGadget(little,
  259.    AttrList(
  260.       GOB_LeftFromLeftOfParent,20,
  261.       GOB_TopFromBottomOfPred,3,
  262.       GOB_Width,90,
  263.       GOB_Height,30,
  264.       GA_Immediate,TRUE,
  265.       GA_RelVerify,TRUE,
  266.       GA_Text,(UBYTE*)" Click ",
  267.       GA_ID, 23,     // will be sent to sendNotification as tag item
  268.       TAG_END) );
  269.  
  270.    stop_window = little;
  271.  
  272.    little->refreshGList();
  273.  
  274.    while (running)
  275.    {
  276.       SignalResponder::WaitSignal();
  277.    }
  278.  
  279.    puts("cleaned up. goodbye.\n");
  280. }
  281.